package library.and.xps.com.step.view.activity;

import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.jude.utils.JUtils;
import com.orhanobut.logger.Logger;
import com.zhy.autolayout.AutoRelativeLayout;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import library.and.xps.com.step.R;
import library.and.xps.com.step.util.AppCommond;
import library.and.xps.com.step.util.CommonUtils;
import library.and.xps.com.step.util.TeamHelper;
import library.and.xps.com.step.view.base.BaseActivity;
import library.and.xps.com.step.view.fragment.ActiveListFragment;

public class TeamActiveActivity extends BaseActivity {

    private ImageView actionbar_iv_back;
    private TextView actionbar_tv_title;
    private TextView actionbar_tv_right;
    private AutoRelativeLayout actionbar_al;
    private ImageView imageView;

    @Override
    protected int getLayout() {
        return R.layout.activity_team_active;
    }

    @Override
    protected void setData() {

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onReceiveEvent(AppCommond a) {
        if (a != null) {
            if (null != a.getAcNameList() && a.getOperation() == AppCommond.CLOSE_ACTIVITY && a.getAcNameList().size() > 0)
                for (String activityName : a.getAcNameList()) {
                    if (activityName.equals(this.getClass().getSimpleName())) {
                        finish();
                        break;
                    }
                }
        }
    }

    @Override
    protected void init() {
        r2v(R.id.v_gap_line).setVisibility(View.VISIBLE);
        actionbar_tv_title = r2v(R.id.actionbar_tv_title);
        actionbar_tv_right = r2v(R.id.actionbar_tv_right);
        actionbar_iv_back = r2v(R.id.actionbar_iv_back);
        actionbar_al = r2v(R.id.actionbar_al);
        actionbar_iv_back.setOnClickListener(this);
        actionbar_tv_right.setOnClickListener(this);
        actionbar_tv_right.setVisibility(View.VISIBLE);

        actionbar_tv_title.setOnClickListener(this);
        actionbar_tv_title.setText("团队活动");

        if (TeamHelper.getIns().getCurT().getRole() == 1)
            addPlusButton();

        CommonUtils.replaceFragment(R.id.container, new ActiveListFragment(), getSupportFragmentManager());

    }

    void addPlusButton() {
        imageView = new ImageView(this);
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(TeamActiveActivity.this, CreateActiveActivity.class));
            }
        });

        imageView.setImageResource(R.mipmap.plus);
        AutoRelativeLayout.LayoutParams layoutParams = new AutoRelativeLayout.LayoutParams(AutoRelativeLayout.LayoutParams.WRAP_CONTENT, AutoRelativeLayout.LayoutParams.MATCH_PARENT);
        layoutParams.addRule(AutoRelativeLayout.ALIGN_PARENT_RIGHT);
        layoutParams.setMargins(40, 40, 25, 40);
        actionbar_al.addView(imageView, layoutParams);

    }

    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.actionbar_al:

                break;
            case R.id.actionbar_tv_title:

                break;
            case R.id.actionbar_iv_back:
                finish();
                break;
            case R.id.actionbar_tv_right:

                break;
        }
    }
}
